<?php
header('Content-Type:text/html;charset=utf-8');
date_default_timezone_set("Asia/Shanghai");
if (!(empty($_POST)))//不为空
{
    $username=isset($_POST["username"]) ? trim($_POST["username"]) : "";
    $password=isset($_POST["password"]) ? trim($_POST["password"]) : "";
    $re=  isset($_POST["re"]) ? trim($_POST["re"]) : false;
    $time=date("y-m-d h:i:sa" , time());
    if (($username==="admin") && ($password==="admin"))
    {
        //成功登录，并且你勾选了记住用户名，将这个用户名天道Cookie
        if($re)
        {
            setcookie("cname",$username,  time()+3600*24);
            setcookie("sj",$time,  time()+3600*24);
        }
        //登录成功
        echo "ok";
    }
 else {
         echo "<script language='javascript' type='text/javascript'>";
        echo "alert('登录失败！');";
        echo "window.location.href='login.php'";
        echo "</script>";
    }
}
 $time=isset($_POST["time"]) ? trim($_POST["time"]) : "";
 setcookie("time",$time,  time()+3600*24);